unit Caixa;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DB, DBTables, Grids, DBGrids, ImgList, ActnList, ComCtrls;

type
  TFormCaixa = class(TForm)
    ListView2: TListView;
    ActTotal: TActionList;
    ActionVoltar: TAction;
    ActionIncluir: TAction;
    ImageList2: TImageList;
    DBGrid1: TDBGrid;
    QueryCaixa: TQuery;
    DataSource1: TDataSource;
    QueryCaixalancamento: TStringField;
    QueryCaixadata: TDateTimeField;
    QueryCaixavalor: TFloatField;
    QueryCaixahistorico: TStringField;
    QueryCaixapagto: TStringField;
    procedure ListView2Click(Sender: TObject);
    procedure FormKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure ActionVoltarExecute(Sender: TObject);
    procedure ActionIncluirExecute(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure QueryCaixavalorGetText(Sender: TField; var Text: String;
      DisplayText: Boolean);
    procedure DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
      DataCol: Integer; Column: TColumn; State: TGridDrawState);
    procedure QueryCaixadataGetText(Sender: TField; var Text: String;
      DisplayText: Boolean);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FormCaixa: TFormCaixa;

implementation

uses IncluirCaixa, Principal;

{$R *.dfm}

procedure TFormCaixa.ListView2Click(Sender: TObject);
var List: TListView;
begin
if TListView(Sender).Selected <> nil then
  begin
        List := TlistView(Sender);
        ActTotal.Actions[List.Selected.StateIndex].Execute;
  end;


end;

procedure TFormCaixa.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if Key = VK_F1 then
     ActionIncluir.Execute;

//  if Key = VK_F2 then
//     ActionEditar.Execute;

//  if Key = VK_F3 then
//     ActionExcluir.Execute;

  if Key = VK_ESCAPE then
     self.close;
end;

procedure TFormCaixa.ActionVoltarExecute(Sender: TObject);
begin
    self.close;
end;

procedure TFormCaixa.ActionIncluirExecute(Sender: TObject);
begin


    if assigned(FormIncluirCaixa) then
       FormIncluirCaixa := nil;

    FormIncluirCaixa := TFormIncluirCaixa.Create(Self);
    FormIncluirCaixa.ShowModal;

    QueryCaixa.ParamByName('p_movimento').AsInteger := FormPrincipal.vIdmovimento;
    QueryCaixa.Close;
    QueryCaixa.Open;



end;

procedure TFormCaixa.FormActivate(Sender: TObject);
begin


    QueryCaixa.ParamByName('p_movimento').AsInteger := FormPrincipal.vIdmovimento;
    QueryCaixa.Open;

    if QueryCaixa.RecordCount = 0 then abort;

end;

procedure TFormCaixa.QueryCaixavalorGetText(Sender: TField;
  var Text: String; DisplayText: Boolean);
begin
    if QueryCaixa.RecordCount = 0 then abort;
    Text := formatfloat('###,###,##0.00', StrToFloat(QueryCaixa.fieldByName('valor').AsString));
end;

procedure TFormCaixa.DBGrid1DrawColumnCell(Sender: TObject;
  const Rect: TRect; DataCol: Integer; Column: TColumn;
  State: TGridDrawState);
var
    holdColor: TColor;
begin
    holdColor := DBGrid1.Canvas.Brush.Color;
    if Column.FieldName = 'lancamento' then
    begin
          if (Trim(Uppercase(Column.Field.AsString)) = 'SUPRIMENTO') then
          begin
             DBGrid1.Canvas.Font.Color := clBlue;
             DBGrid1.Canvas.Font.Style := [fsBold];
             DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
             DBGrid1.Canvas.Brush.Color := holdColor;
          end;

          if (Trim(Uppercase(Column.Field.AsString)) = 'ABERTURA') then
          begin
             DBGrid1.Canvas.Font.Color := clBlue;
             DBGrid1.Canvas.Font.Style := [fsBold];
             DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
             DBGrid1.Canvas.Brush.Color := holdColor;
          end;

          if (Trim(Uppercase(Column.Field.AsString)) = 'SANGRIA') then
          begin
             DBGrid1.Canvas.Font.Color := clRed;
             DBGrid1.Canvas.Font.Style := [fsBold];
             DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
             DBGrid1.Canvas.Brush.Color := holdColor;
          end;

          if (Trim(Uppercase(Column.Field.AsString)) = 'PEDIDO') then
          begin
             DBGrid1.Canvas.Font.Color := clGreen;
             DBGrid1.Canvas.Font.Style := [fsBold];
             DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
             DBGrid1.Canvas.Brush.Color := holdColor;
          end;

          if (Trim(Uppercase(Column.Field.AsString)) = 'VALE') then
          begin
             DBGrid1.Canvas.Font.Color := clMaroon;
             DBGrid1.Canvas.Font.Style := [fsBold];
             DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
             DBGrid1.Canvas.Brush.Color := holdColor;
          end;
    end;

end;

procedure TFormCaixa.QueryCaixadataGetText(Sender: TField;
  var Text: String; DisplayText: Boolean);
begin

    Text := FormPrincipal.FormataData(QueryCaixa.fieldByName('data').AsDateTime,3)
end;

end.
